#include "ZBHeroManager.h"

int ZBHeroManager::whichHero(BWAPI::Position p)
{
	int x = p.x();
	int y = p.y();
	
	if(x >= MARINEX1 && x <= MARINEX2 && y >= MARINEY1 && y <= MARINEY2)
	{
		numSpent += 1;
		if(numSpent == MARINECOST)
		{
			numSpent = 0;
			return ZBMARINE;
		}
		else
		{
			return -1;
		}
	}
	if(x >= FIREBATX1 && x <= FIREBATX2 && y >= FIREBATY1 && y <= FIREBATY2)
	{
		numSpent += 1;
		if(numSpent == FIREBATCOST)
		{
			numSpent = 0;
			return ZBFIREBAT;
		}
		else
		{
			return -1;
		}
	}
	if(x >= DARKTEMPLARX1 && x <= DARKTEMPLARX2 && y >= DARKTEMPLARY1 && y <= DARKTEMPLARY2)
	{
		numSpent += 1;
		if(numSpent == DARKTEMPLARCOST)
		{
			numSpent = 0;
			return ZBDARKTEMPLAR;
		}
		else
		{
			return -1;
		}
	}
	if(x >= ZEALOTX1 && x <= ZEALOTX2 && y >= ZEALOTY1 && y <= ZEALOTY2)
	{
		numSpent += 1;
		if(numSpent == ZEALOTCOST)
		{
			numSpent = 0;
			return ZBZEALOT;
		}
		else
		{
			return -1;
		}
	}
	if(x >= ARCHONX1 && x <= ARCHONX2 && y >= ARCHONY1 && y <= ARCHONY2)
	{
		numSpent += 1;
		if(numSpent == ARCHONCOST)
		{
			numSpent = 0;
			return ZBARCHON;
		}
		else
		{
			return -1;
		}
	}
	if(x >= ZERGLINGX1 && x <= ZERGLINGX2 && y >= ZERGLINGY1 && y <= ZERGLINGY2)
	{
		numSpent += 1;
		if(numSpent == ZERGLINGCOST)
		{
			numSpent = 0;
			return ZBLING;
		}
		else
		{
			return -1;
		}
	}
	if(x >= DRAGOONX1 && x <= DRAGOONX2 && y >= DRAGOONY1 && y <= DRAGOONY2)
	{
		numSpent += 1;
		if(numSpent == DRAGOONCOST)
		{
			numSpent = 0;
			return ZBDRAGOON;
		}
		else
		{
			return -1;
		}
	}
	if(x >= OBSERVERX1 && x <= OBSERVERX2 && y >= OBSERVERY1 && y <= OBSERVERY2)
	{
		numSpent += 1;
		if(numSpent == OBSERVERCOST)
		{
			numSpent = 0;
			return ZBOBSERVER;
		}
		else
		{
			return -1;
		}
	}
	if(x >= GHOSTX1 && x <= GHOSTX2 && y >= GHOSTY1 && y <= GHOSTY2)
	{
		numSpent += 1;
		if(numSpent == GHOSTCOST)
		{
			numSpent = 0;
			return ZBGHOST;
		}
		else
		{
			return -1;
		}
	}
	if(x >= ULTRALISKX1 && x <= ULTRALISKX2 && y >= ULTRALISKY1 && y <= ULTRALISKY2)
	{
		numSpent += 1;
		if(numSpent == ULTRALISKCOST)
		{
			numSpent = 0;
			return ZBULTRALISK;
		}
		else
		{
			return -1;
		}
	}
	if(x >= KERRIGANX1 && x <= KERRIGANX2 && y >= KERRIGANY1 && y <= KERRIGANY2)
	{
		numSpent += 1;
		if(numSpent == KERRIGANCOST)
		{
			numSpent = 0;
			return ZBKERRIGAN;
		}
		else
		{
			return -1;
		}
	}
	if(x >= SIEGETANKX1 && x <= SIEGETANKX2 && y >= SIEGETANKY1 && y <= SIEGETANKY2)
	{
		numSpent += 1;
		if(numSpent == SIEGETANKCOST)
		{
			numSpent = 0;
			return ZBSIEGETANK;
		}
		else
		{
			return -1;
		}
	}
	if(x >= LURKERX1 && x <= LURKERX2 && y >= LURKERY1 && y <= LURKERY2)
	{
		numSpent += 1;
		if(numSpent == LURKERCOST)
		{
			numSpent = 0;
			return ZBLURKER;
		}
		else
		{
			return -1;
		}
	}
	if(x >= HYDRALISKX1 && x <= HYDRALISKX2 && y >= HYDRALISKY1 && y <= HYDRALISKY2)
	{
		numSpent += 1;
		if(numSpent == HYDRALISKCOST)
		{
			numSpent = 0;
			return ZBHYDRALISK;
		}
		else
		{
			return -1;
		}
	}
	return 0;
}
